#-----------------------------------------------------------------------------
# Name:        EventScripts IDE
# Purpose:     An IDE for the EventScripts language written in Python
#
# Author:      Thomas Morton
#
# Created:     04/05/2008
# Copyright:   (c) 2008 Thomas Morton
# Licence:     Free
#-----------------------------------------------------------------------------


'''

ES IDE is the basis of an IDE for the EventScripts language.

At this time it is a basic command line program to launch various other packages

This program implements the following features:
    [*] PySrcds: Source server emulator with basic ES emulator
    [*] Utilities: Stuff to make it work!
        [*] Environment: Allows different users to use the program (eventually this will be implemented via the web!!)

Other planned features are:
    [*] GUI front end
    [*] Server GUI for the emulator
    [*] Script editor with syntax highlighting (for ESS and ESP) and IDE feratures
    [*] One click testing of scripts
    [*] "Project" mamagement, build, test and package ESS and ESP addons from one program
    [*] Collaboration: SVN style multi-user projects via the web
    [*] DocES: EventScripts api documentation
    [*] Server monitor: monitor your local and remote test servers, manage their files and cfgs
    
Addons (ES addons for your server that will tie in with this program):
    [*] Addon Utils: manage your addons on the server
    [*] Server Mode: change the mode of the server for test purposes
    [*] Server Utils: Setup your server in game!
    [*] Clan Manager: an auth manager where settings can be edited via ES-IDE GUI
    
 == About ==

 Ever since I was let into the ES release team / private beta and found out about Python support I have had idea
 after idea of amazing features / stuff that can now be written for ES. At the start I considered Python as JUST
 and ES language, however after a few months I came to realise that it is a simply wonderful language to code in.
 Almost like writing a novel in code!
 
 So I began to look outside of just ES modules and what could be written for ES/Srcds in pure Python.
 
 One of my first ever ideas was a SRCDS + ES2 emulator that you could use to load up your addons and test without
 the tediumm (and huge space requirements) of setting up a test server. However my Python ability was far too low 
 to consider doing such a thing. Slowly more ideas came; server utilities, addons utilities, monitors, clan adminsitration.
 Finally it all came together recently when I discovered I now COULD program the emulator.
 
 So after a 6 month incubation period ES IDE was concieved and the first code laid down. Lets hope it grows from here :)
 
 == Legal ==
 
 This software is totally open source and freely available for editing / distribution.
 Credit would be appreciated in derivatives but not required. Please do not SELL this
 software: it's just not cricket!
 
 If you make changes or improvements please let me know so they can be incorporated into
 the release.
 
 == Ethos ==
 
            ** Release early release often **
 (It's an ideal employed by Google so it has to be good :D)
 
 Also:
         ** Incremental revisions reduces bugs **
 
 This software was created for fun as well as for a purpose, everything is commented 
 where possible to help others understand this fantastic language.

 ES IDE and it's modules are written with OOP and "Python standards" in mind :)
 
  == Credits ==
  
  ** The following third party modules are used in this program **
  ** they can be found in the third_party folder of the compressed library **
    [*] Path: http://jorendorff.com/articles/python/path/
            Jason Orendorff's sublime and easy to use path library (so I didnt have to use os.path!)
    [*] ConfigObj: http://www.voidspace.org.uk/python/configobj.htm
            The ONLY way to read INI files :)
    [*] Md5Crypt: http://www.sabren.net/code/python/crypt/
            Michal j wallace: a crypt library for storing passwords and the like (in Environment)
  
  ** The following people were important in this *
    [*] Mattie: for getting me into Pytho nand for ES
    [*] SuperDave: for teaching me stuff I didnt know about Python
  
'''
from utilities import Environment,logging

from third_party.path import path

import zipfile

# assign some imports for easier code reading
log = logging.log
this = Environment.this
def print_file(file):
    '''
        Outputs a files contents (path object) to the console
    '''
    for line in file.lines():
        if not line.startswith("//"):
            print line.strip("\n")
            
# ok let's go!
# load the program environment
log(0,"   ---------------        ")
log(0,"   New logfile entry      ")
log(0,"   ---------------        ")
log(0,"** Program initialisation")
log(0,"** Init program Environment")


if this.status == 0:
    log(0,"** Unable to open program environment cfg, attempting first tiime install")
    from utilities.install import Installer
    i = Installer()
    i.unzip_datapath()
    # ok now we need a user input!
    print_file(Environment.datapath / "txt/install.txt")
    uname = raw_input("Please enter a name for the master profile:")
    while uname == "default":
        print "#### Sorry that username is protect, please choose another"
        uname = raw_input("Please enter a name for the master profile:")
    user = Environment._UserEnvironment(uname)
    user.create()
    


# grab the startup user if they are set
user = Environment.startup_user()

# output the first bit of info
print_file(Environment.datapath / "txt/intro.txt")
# ah we need to make a new user or login
if not user:
    raw_input("Login: ")